package imageEditor.utility;

import java.awt.Point;
import java.io.Serializable;

public class Point2d implements Serializable{
	private int x,y;
	
	public Point2d(){
		x=y=0;
	}
	
	public Point2d(int x, int y){
		this.x=x;
		this.y=y;
	}

	public Point2d(Point p1) {
		this(p1.x,p1.y);
	}

	public Point2d(Point start, Point p1) {
		this(p1.x-start.x,p1.y-start.y);
	}

	public Point2d(int[] p) {
		this(p[0],p[1]);
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public void plus(Point2d vect) {
		x+=vect.x;
		y+=vect.y;
	}
	
	public String toString(){
		return x+","+y;
	}
	
	public static Point2d fromString(String s){
		Point2d ret=new Point2d();
		String[] split=s.split(",");
		try{
			ret.x=Integer.parseInt(split[0]);
			ret.y=Integer.parseInt(split[1]);
		}catch(Exception ex){}
		
		return ret;
	}
	
}
